package com.yangdage.controller;

import com.yangdage.service.MQService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/***
 * 来源 https://mp.weixin.qq.com/s/0XdwZTkO6da2o5Jgf20wvg
 *
 */
@RestController
@RequestMapping(value = "/api")
public class RedisMQController {
    @Resource
    private MQService mQService;

    @RequestMapping(value = "/produce", method= RequestMethod.GET)
    public void produce(@RequestParam(name = "key") String key) {
        mQService.produce(key);
    }

    @RequestMapping(value="/consume", method=RequestMethod.GET)
    public void consume() {
        while (true) {
            mQService.blockingConsume();
        }
    }
}
